﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsGame4
{
    class Enemy_InitialState : State
    {
        private static Enemy_InitialState instance;

        private Enemy_InitialState()
        {
            base.Name = "InitialState";
        }

        public override void enter(AIObject aiObject)
        {
            //System.Console.WriteLine("enemyenteriitial");
            AIEnemy aiEnemy = (AIEnemy)aiObject;
            Enemy enemy = (Enemy)aiEnemy.Enemy;
            enemy.Blinking = true;
            EventEmitter.getInstance().registerMessage(50000000, aiEnemy.Id, aiEnemy.Id, Message.MessageType.msg_disableBlinking);
        }

        public static Enemy_InitialState getInstance()
        {
            if (instance == null)
                instance = new Enemy_InitialState();
            return instance;
        }

        public override void execute(AIObject aiObject)
        {
            //System.Console.WriteLine("enemyexecuteinitial");
            AIEnemy aiEnemy = (AIEnemy)aiObject;
            Enemy enemy = (Enemy)aiEnemy.Enemy;
            GameInfo gameInfo = GameInfo.getInstance();

            EventEmitter.getInstance().registerMessage(0, aiEnemy.Id, aiEnemy.Id, Message.MessageType.msg_stop);
            //System.Console.WriteLine("exitenemyexecuteinitial");
        }

        public override void exit(AIObject aiObject)
        {

        }

        public override Boolean onMessage(AIObject aiObject, Message message)
        {
            Boolean correct = false;
            switch (message.Type)
            {
                case Message.MessageType.msg_stop:
                    {
                        aiObject.StateMachine.changeState(Enemy_StopState.getInstance());
                        correct = true;
                        break;
                    }
                case Message.MessageType.msg_disableBlinking:
                    {
                        AIEnemy aiEnemy = (AIEnemy)aiObject;
                        Enemy enemy = (Enemy)aiEnemy.Enemy;
                        enemy.Blinking = false;
                        correct = true;
                        break;
                    }
            }
            return correct;
        }
    }
}